package com.huike.web.controller.business;

import com.huike.business.domain.TbBusinessTrackRecord;
import com.huike.business.domain.TbBusinessTrackRecordVO;
import com.huike.business.service.ITbBusinessService;
import com.huike.clues.service.ISysDictDataService;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/business/record")
public class TbBusinessTrackRecordController extends BaseController {

    @Autowired
    private ITbBusinessService tbBusinessService;

    @Autowired
    private ISysDictDataService sysDictDataService;

    @GetMapping("/list")
    public AjaxResult list(@RequestParam("businessId") Long businessId) {
        List<TbBusinessTrackRecord> list = tbBusinessService.selectTbBusinessTrackRecordList(businessId);
        for (TbBusinessTrackRecord businessTrackRecord : list) {
            String[] items = businessTrackRecord.getKeyItems().split(",");
            for (String item : items) {
                String dictLable = sysDictDataService.selectDictLabel("communication_point", item);
                businessTrackRecord.getKeys().add(dictLable);
            }
        }
        return AjaxResult.success(list);
    }


    @PostMapping
    public AjaxResult addTbBusinessTrackRecord(@RequestBody TbBusinessTrackRecordVO vo){
        int row = tbBusinessService.addTbBusinessTrackRecord(vo);
        return toAjax(row);
    }

}
